package peer.dstdb.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteIntSwitch;
import peer.tools.ByteShortSwitch;

public class CastAddMessage2 extends Message{
	public short sType=peer.tools.MessageType.sType_DB_CastAddMessage2;
	int sourceSessionId;
	byte[] dpData=null;
	public CastAddMessage2(int sourceSessionId){
		byte[] dpData=new byte[8];
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		ByteIntSwitch.toByteArray(sourceSessionId, dpData, 4);
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public int getSourceSessionId(){
		return sourceSessionId;
	}
	
	public CastAddMessage2(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		sourceSessionId=ByteIntSwitch.toInt(dpData, 4);
	}
}
